<?php
function GetContent($page_id='id_btn_home',$pageNum,$category_id=0,$campaign_id=0) {
    global $smarty;
    global $gCn;

    switch($page_id) {
        case 'id_btn_home':


            break;
        case 'id_btn_portfolio':
            if($pageNum>0) $pageNum-=1;
            if($category_id>0) $where='where category_id='.$category_id;
            if($campaign_id>0) {
                $where='join campaign_objects co on co.object_id=o.object_id where campaign_id='.$campaign_id;
                $smarty->assign('campaign_objects',1);
            }
            $order_by = 'ORDER BY orderby DESC';
            $sql = 'select o.* from objects o '.$where.' '.$order_by.' offset '.($pageNum*9).' limit 9;';
            $gCn->Execute($sql);
            $arrObjects=array();

            while(!$gCn->EOF()) {
                $items++;
                $arrObjects[$gCn->mRs['object_id']]=array(
                        'name'=>$gCn->mRs['name'],
                        'url'=>$gCn->mRs['url'],
                        'thumb_src'=>preg_replace('/(\.[a-zA-Z]{3,4})/', '_t${1}', $gCn->mRs['thumb_src']),
                        'type_id'=>$gCn->mRs['type_id']
                );
                $gCn->MoveNext();
            }

            //stranicirane
            // if($category_id>0) {
            $sqlCNT = 'select COUNT(*) as cnt from objects '.$where.' ;';
            // break;
            $gCn->Execute($sqlCNT);
            $gCn->MoveFirst();

            $itemsCNT = $gCn->mRs['cnt'];
            $pages = ceil($itemsCNT / 9);

            if ($pages<=1) $pages = false;
            else {
                $pages = range(1, $pages);
                $pages = array_combine($pages,$pages);
            }

            $smarty->assign('pages',$pages);
            // }
            //stranicirane KRAI
            $smarty->assign('objects',$arrObjects);
            break;
        case 'id_btn_clients':
            $sql='select * from clients WHERE client_id > 0 ORDER BY RANDOM();';
            $gCn->Execute($sql);
            $gCn->MoveFirst();
            $arrObjects=array();
            while(!$gCn->EOF()) {
                $arrObjects[$gCn->mRs['client_id']]=array(
                        'name'=>$gCn->mRs['name'],
                        'logo_src'=>$gCn->mRs['logo_src']
                );
                $gCn->MoveNext();
            }
            $smarty->assign('objects',$arrObjects);
            break;
        case 'id_btn_campaigns':
            $sql='select c.*,cl.name as client_name from campaigns c join clients cl on c.client_id=cl.client_id order by campaign_id desc;';
            $gCn->Execute($sql);
            $gCn->MoveFirst();
            $arrObjects=array();
            $cnt=1;
            while(!$gCn->EOF()) {
                switch($cnt%4) {
                    case 1:$color='yellow';
                        break;
                    case 2:$color='red';
                        break;
                    case 3:$color='green';
                        break;
                    case 0:$color='blue';
                        break;
                }
                $arrObjects[$gCn->mRs['campaign_id']]=array(
                        'name'=>$gCn->mRs['name'],
                        'thumb_src'=>$gCn->mRs['thumb_src'],
                        'descr'=>$gCn->mRs['descr'],
                        'client_id'=>$gCn->mRs['client_id'],
                        'client_name'=>$gCn->mRs['client_name'],
                        'color'=>$color
                );
                $cnt++;
                $gCn->MoveNext();
            }
            $smarty->assign('objects',$arrObjects);
            break;
    }

}



?>
